// pages/zlk/zlk.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    session_key:'',
    tabCur: 0, //默认选中
    tabs: [{
        name: '公务员',
        id: 0
      },
      {
        name: '事业单位',
        id: 1
      },
      {
        name: '医疗招聘',
        id: 2
      },
      {
        name: '法检',
        id: 3
      },
      {
        name: '军队文职',
        id: 4
      },
      {
        name: '考研',
        id: 5
      },
      {
        name: '遴选',
        id: 6
      },
      {
        name: '三支一扶',
        id: 8
      },
      {
        name: '社区招聘',
        id: 9
      },
      {
        name: '招警',
        id: 10
      },
      {
        name: '中级会计',
        id: 11
      },
      {
        name: '中级经济师',
        id: 12
      },
      {
        name: '注会',
        id: 13
      }
    ],
    list: 0,
    lists: [
      [{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/gwy.png',
        title: '2021年山东公务员行测公式大全',
        sid: 1
      }],
      [{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/sydw.png',
        title: '2020全年时政大全划重点版',
        sid: 2
      },{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/sydw.png',
        title: '2020全年时政汇总',
        sid: 3
      }],
      [{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/ylzp.png',
        title: '《卫生公基》模拟卷',
        sid: 4
      }, {
        img: 'http://sd.offcn.com/zg/wximg/hb-img/ylzp.png',
        title: '《医学基础知识》常考知识点&经典例题',
        sid: 5
      }],
      [{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/fj.png',
        title: '法检、书记员备考手册',
        sid: 6
      }, {
        img: 'http://sd.offcn.com/zg/wximg/hb-img/fj.png',
        title: '法检、书记员模拟卷1',
        sid: 7
      }, {
        img: 'http://sd.offcn.com/zg/wximg/hb-img/fj.png',
        title: '法检、书记员模拟卷2',
        sid: 8
      }],
      [{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/jdwz.png',
        title: '2021年军队文职《公共科目》备考手册',
        sid: 9
      }],
      [{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/ky.png',
        title: '2021考研7种方法帮你克服考研复试面试紧张',
        sid: 10
      },{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/ky.png',
        title: '男女生关于面试礼仪等8大注意事项',
        sid: 11
      },{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/ky.png',
        title: '复试简历准备要点',
        sid: 12
      }],
      [{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/lx.png',
        title: '遴选笔试模拟卷',
        sid: 13
      },{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/lx.png',
        title: '遴选核心考点',
        sid: 14
      },{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/lx.png',
        title: '遴选是什么',
        sid: 15
      }],
      [{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/szyf.png',
        title: '2020山东三支一扶考试市场卷2套-公基+申论-卷1-答案版',
        sid: 16
      },{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/szyf.png',
        title: '2020山东三支一扶考试市场卷2套-公基+申论-卷1-学生版',
        sid: 17
      }],
      [{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/sqzp.png',
        title: '2020山东社区工作者备考手册+模拟卷',
        sid: 18
      }],
      [{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/zj.png',
        title: '招警考试备考手册',
        sid: 19
      },{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/zj.png',
        title: '招警辅警模拟卷1',
        sid: 20
      },{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/zj.png',
        title: '招警辅警模拟卷2',
        sid: 21
      }],[{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/zjkj.png',
        title: '中级经济法-高频考点',
        sid: 22
      },{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/zjkj.png',
        title: '中级会计实务-高频考点',
        sid: 23
      },{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/zjkj.png',
        title: '中级财管-高频考点汇总',
        sid: 24
      }],[{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/zjjjs.png',
        title: '财税专业-重点知识点梳理',
        sid: 25
      }],[{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/zk.png',
        title: '注会千题-战略',
        sid: 26
      },{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/zk.png',
        title: '注会千题-税法',
        sid: 27
      },{
        img: 'http://sd.offcn.com/zg/wximg/hb-img/zk.png',
        title: '注会千题-经济法',
        sid: 28
      }],
    ],
    page:34

  },
  topdf(e) {
    var that = this;
    var phone = wx.getStorageSync('zlphone')
    if(phone){
      console.log(e.currentTarget.dataset.sid)
      var sid = e.currentTarget.dataset.sid;
      wx.navigateTo({
        url: '../pdf/pdf?sid=' + sid,
      })
    } else {
      wx.showToast({
        title: '请先登录',
        icon: 'none',
        duration: 2000
      });
      that.setData({
        login:1
      })
    }
  },

  getPhoneNumber(e) {
    var that = this;
    console.log(e.detail.iv)
    console.log(e.detail.encryptedData)

    wx.request({
      url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/program/get_phone_num',
      method: 'POST',
      data: {
        id: 24,
        page_id:34,
        iv:e.detail.iv,
        encryptedData:e.detail.encryptedData,
        sessionKey:that.data.session_key
      },
      success: res => {
        console.log(res.data.phoneNumber);
        wx.setStorageSync('zlphone', res.data.phoneNumber)
        wx.request({ //发送请求
          url: 'https://zg99.offcn.com/index/biaodan/register?actid=33261&callback=?', //接收url
          data: {
              phone: res.data.phoneNumber,
              fenxiao: that.data.area,
              geneal: that.data.geneal,
          }, //接收参数
          success(res) {
              var jsonStr = res.data;
              jsonStr = jsonStr.replace("(", "");
              jsonStr = jsonStr.replace(")", "");
              if (typeof jsonStr != 'object') {
                  jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                  var theJson = JSON.parse(jsonStr);
              }
              console.log(theJson)
              that.setData({
                  login: 0
              })
          }
      });
      wx.request({
          url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/wx_collect_info',
          method: 'POST',
          data: {
              activity_id: 24,
              mobile: res.data.phoneNumber,
              area_code: that.data.area,
              agent: that.data.geneal,
              page_index: that.data.page
          },
          success: res => {
              console.log(res);
          }
      })
     
      }
    })
   
  },

  //选择条目
  tabSelect(e) {
    console.log(e.currentTarget.dataset.id)
    this.setData({
      list: e.currentTarget.dataset.id,
      tabCur: e.currentTarget.dataset.id,
      scrollLeft: (e.currentTarget.dataset.id - 2) * 200
    })
  },
  tohb(){
    wx.navigateTo({
      url: '../tuiwen/tuiwen',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log(options);
    that.setData({
      area: options.area,
      geneal: options.agent
    })
    if (options.page) {
      that.setData({
        page: options.page
      })
    }

    wx.login({
      success (res) {
        console.log(res)
        if (res.code) {
          wx.request({
            url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/program/wx_login',
            method:'POST',
            data: {
              code: res.code,
              id: 24
            },
            success: res => {
              console.log(res.data.session_key);
              that.setData({
                session_key : res.data.session_key
              })
            }
          })
        } else {
          console.log('登录失败！' + res.errMsg)
        }
      }
    })
  }
})